package com.linkpow.smartelevator.controller;

import com.linkpow.smartelevator.req.ReqUserDto;
import io.swagger.annotations.*;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName TestController
 * @Description 环境测试
 * @Author 王丹
 * @Date 2019/11/25 16:51
 * @Version 1.0
 */
@RestController
@RequestMapping("test")
@Validated
@Api(tags = "环境用户测试")
public class TestController {

    @GetMapping(value="query", produces="application/json")
    @ApiOperation(value = "用户信息", notes = "查询用户详细信息")
    public Map query(@NotNull(message = "用户ID不能为空") @RequestParam(required = false) Integer id){
        Map ret = new HashMap();
        ret.put("id", id);
        ret.put("name", "见附件款四大皆空了");
        return ret;
    }

    @GetMapping(value="queryList", produces=MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户列表", notes = "查询用户列表")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "query", name = "id", required = false, value = "用户ID", defaultValue = "0", dataType = "integer"),
        @ApiImplicitParam(paramType = "query", name = "account", value = "账号", dataType = "String")
    })
    public List<ReqUserDto> queryList(@RequestParam(required = false) @NotEmpty(message = "account不能为空") String account, @RequestParam(required = false) Integer id){
        List<ReqUserDto> ret = new ArrayList<>();
        ReqUserDto user1 = new ReqUserDto();
        user1.setId(id);
        user1.setAccount(account);
        user1.setName("测试管理员");
        ret.add(user1);
        return ret;
    }

    @PostMapping(value="save", consumes="application/json", produces="application/json")
    @ApiOperation(value = "保存", notes = "保存用户数据")
    public ReqUserDto save(@Valid @RequestBody ReqUserDto reqUserDto){
        return reqUserDto;
    }

    @DeleteMapping(value = "/del/{id}", produces=MediaType.TEXT_PLAIN_VALUE)
    @ApiOperation(value = "删除", notes = "删除用户信息")
    public String del(@NotNull(message = "用户ID不能为空") @PathVariable("id") Integer id){
        return "删除成功";
    }

}
